package net.lzzy.practices.utils;

import com.alibaba.fastjson.JSONObject;
import net.lzzy.practices.web.models.BaseInfo;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;

import static org.springframework.beans.BeanUtils.getParameterNames;

/**
 * @author m
 */
public class AspectUtil {

    private  static  final  String ARG_TOKEN= "token";

    public  static  String getTokrn(ProceedingJoinPoint point) {
        Object[] args= point.getArgs();
        int i=0;
        String[] names=((MethodSignature)point.getSignature()).getParameterNames();
        //1
        for(String namr : names){
            if(ARG_TOKEN.equals(names)){
                return args[i].toString();
            }
            i++;
        }
        //2
        if(args[0] instanceof BaseInfo){

            return  ((BaseInfo)args[0]).getToken();
        }else {
            //3
            JSONObject obj= (JSONObject)  args[0];
            return  obj.getString(ARG_TOKEN);
        }
    }
}
